$(function(){
		/*初始化表格*/
		$('#trainBase').datagrid({
    		url:'backtrainbasejson',
    		collapsible:true,
    		fit:true,
			fitColumns:true,
			toolbar:'#footer',
			pagination:true,
			pageSize:20,
			pageList:[20,50,100,200],
			remoteSort:false,
   			columns:[[
   			 	{field:'ck',checkbox:true},
   			 	{field:'trainID',hidden:'true'},
			{field:'trainName',title:'列车名称',align:'center',width:'40%'},
				{field:'memo',title:'备注',align:'center',width:'58%'}
    		]]
		});
			
});

/*搜索*/
function searchTrainBase(){
	
		var trianName = $("#searchTrainBaseName").val();
	
		$("#trainBase").datagrid("load",{
			trianName:trianName,
			
		})
	}
	
/*清空*/
function clearTrainBase(){
        $("#searchTrainBaseName").val('');
		
     }


// 修改航班信息
function updateTrainBase() {
	
	
		var rows = $('#trainBase').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
			//判断创建人所属公司是否相同  登陆人与创建人公司相同
			var travelOrgID = rows[0].spare1;
			var sessionOrgID=$("#sessionOrgID").val();
			if(parseInt(travelOrgID)==parseInt(sessionOrgID)){
		$.messager.confirm('Confirm', '确定要修改吗?', function(r){
	if (r){
		var iTrainID = rows[0].trainID; 
		 	location.href="/mmy/backtoupdatetrainbase?iTrainID="+iTrainID;
	}
});
	}else{
		$.messager.alert('错误','无法修改','error');
		
	}	
		 }
}



/*进入航班时刻页面*/
function toTrainPlan(){
	var rows = $('#trainBase').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
				var iTrainID = rows[0].trainID;  
				location.href="/mmy/backtotrainplanindex?iTrainID="+iTrainID;
			}
}

